package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.CertificationAgencyCode;
import com.shrcl.engineerprocess.domain.CertificationMaintainerByAgency;
import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.impl.CertificationAgencyCodeImpl;
import com.shrcl.engineerprocess.domain.impl.EngineerImpl;
import com.shrcl.engineerprocess.domain.proxy.CertificationMaintainerByAgencyProxy;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("CERTIFICATIONMAINTAINERBYAGENCY_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "certificationmaintainerbyagency")
public class CertificationMaintainerByAgencyImpl extends BaseModelObject implements CertificationMaintainerByAgency {
  public CertificationMaintainerByAgencyImpl() {
    super();
  }
  
  @JoinColumn(name = "agency_id")
  @ManyToOne(targetEntity = CertificationAgencyCodeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private CertificationAgencyCode agency;
  
  public CertificationAgencyCode getAgency() {
    return this.agency;
  }
  
  public CertificationMaintainerByAgency setAgency(final CertificationAgencyCode agency) {
    this.agency = agency;
    return this;			
    
  }
  
  @JoinColumn(name = "maintainer_id")
  @ManyToOne(targetEntity = EngineerImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private Engineer maintainer;
  
  public Engineer getMaintainer() {
    return this.maintainer;
  }
  
  public CertificationMaintainerByAgency setMaintainer(final Engineer maintainer) {
    this.maintainer = maintainer;
    return this;			
    
  }
  
  public void checkValid() {
    boolean _notEquals = (!Objects.equal(this.agency, null));
    Validates.Assert(_notEquals, "\u53D1\u8BC1\u673A\u6784\u4E0D\u80FD\u4E3A\u7A7A");
  }
  
  public static CertificationMaintainerByAgency create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.CertificationMaintainerByAgency certificationMaintainerByAgency = new com.shrcl.engineerprocess.domain.impl.CertificationMaintainerByAgencyImpl(
    );
    objectFactory.create(certificationMaintainerByAgency);
    return certificationMaintainerByAgency;			
    
  }
  
  public static CertificationMaintainerByAgency createCertificationMaintainerByAgencyImpl(final IObjectFactory objectFactory, final Procedure1<CertificationMaintainerByAgency> init) {
    com.shrcl.engineerprocess.domain.CertificationMaintainerByAgency certificationMaintainerByAgency = new com.shrcl.engineerprocess.domain.impl.CertificationMaintainerByAgencyImpl(
    );
    objectFactory.create(certificationMaintainerByAgency);
    init.apply(certificationMaintainerByAgency);
    
    return certificationMaintainerByAgency;			
    
  }
  
  public CertificationMaintainerByAgencyProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.CertificationMaintainerByAgencyProxy proxy = new com.shrcl.engineerprocess.domain.proxy.CertificationMaintainerByAgencyProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
